function arrToTree(arr) {
    let map = new Map();
    arr.forEach(item => map[item.id] = item);

    let root = []
    arr.forEach(item => {
        // if (item.pid) {
        //     if (map[item.pid].children) {
        //         map[item.pid].children = []
        //     }
        //     map[item.pid].children.push(item)
        // } else {
        //     root.push(item)
        // }
        const parent = map[item.pid];
        if(parent){
            (parent.children || (parent.children = [])).push(item)
        }else {
            root.push(item)
        }
    })
    return root
}